package atom.core3.app.server;

import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import org.apache.log4j.Logger;
import org.springframework.transaction.CannotCreateTransactionException;
import org.springframework.transaction.TransactionSystemException;

import atom.core0.app.thread.daemon.BaseDaemonThread;

public class SpringDBAppServer extends BaseDaemonThread
{
	private static Logger	          logger	   = Logger.getLogger("demoapp");

	private static ThreadPoolExecutor	threadPool	= new ThreadPoolExecutor(5, 10, 3, TimeUnit.SECONDS,
	                                                       new SynchronousQueue<Runnable>(),
	                                                       new ThreadPoolExecutor.CallerRunsPolicy());

	public void doProcess() throws InterruptedException,Exception
	{
		try
		{
		}
		catch (RuntimeException e)
		{
			//1 要控制数据库连接异常  是否退出，还是重连
			logger.error("命令执行出错啦,可能数据库连接出错");
			logger.error(e, e);
		}
	}
	public boolean doProcessException(Throwable t)
	{
		if (t instanceof CannotCreateTransactionException )
		{
			logger.warn("轮询服务" + this.getName() + "遇到数据库连接异常1,稍后重连");
			return true;
		}
		else if (t instanceof TransactionSystemException )
		{
			logger.warn("轮询服务" + this.getName() + "遇到数据库连接异常2,稍后重连");
			return true;
		}
		return false;
	}
}
